#!/bin/bash
### BEGIN INIT INFO
# Provides:          ssocksd
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the ssocks daemon with /etc/ssocksd.conf as config file
# Description:       not available
### END INIT INFO

# Source function library.
. /etc/init.d/functions

RETVAL=0
PID_FILE=/var/run/ssocksd.pid
SSOCKSD=/usr/local/bin/ssocksd
SSOCKSD_CONFIG=/usr/local/etc/ssocksd.conf 
start() {
    #echo "starting ssocksd"
	#$SSOCKSD --file SSHD_CONFIG -d
    #return "$RETVAL"
	[ -x $SSOCKSD ] || exit 5
	[ -f $SSOCKSD_CONFIG ] || exit 6
	
	$SSOCKSD --file $SSOCKSD_CONFIG -d && success || failure
	RETVAL=$?
	[ $RETVAL -eq 0 ]
	echo
	return $RETVAL

}

stop() {
	echo "stopping ssocksd"
	killproc -p $PID_FILE $SSOCKSD
	RETVAL=$?
	return $RETVAL
    #return "$RETVAL"
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|force-reload)
	stop
	sleep 3
	start
	;;
  status)
	ps aux | grep "$SSOCKSD" | grep -v grep
	;;
  reload)
	exit 3
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|status|force-reload}"
	exit 2
esac

exit "$RETVAL"

